home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 October / EnigmA AMIGA RUN 31 (1998)(G.R. Edizioni)(IT)[!][issue 1998-10].iso / earkit / chat / amarquee / examples / amarqueedebug.rexx < prev    next >
OS/2 REXX Batch file  |  1998-09-22  |  7KB  |  180 lines

  1. /*************************************************
  2.  
  3.    AMarqueedebug.rexx
  4.  
  5.    Author: Jeremy Friesner (jaf@chem.ucsd.edu)
  6.    
  7.    An ARexx implementation of amarqueedebug.c.  Works pretty much
  8.    the same as the C version does!  Requires amarquee.library
  9.    v46 or higher.
  10.  
  11.    Usage:  rx amarqueedebug.rexx [serverName] [portNumber] [logName]
  12.    
  13. ***************************************************/
  14.  
  15. parse arg serverName portNum logName .
  16.  
  17. if (serverName == '?') then do
  18.   say "Usage: rx amarqueedebug.rexx [serverName] [portNum] [logName]"
  19.   say "       (defaults args are localhost 2957 amarqueedebug.rexx)"
  20.   exit
  21.   end
  22.   
  23. if (length(serverName) = 0) then serverName = 'localhost'
  24. if (length(portNum) = 0)    then portNum    = 2957
  25. if (length(logName) = 0)    then logName    = 'amarqueedebug.rexx'
  26.  
  27. /* We need to trap all the different ways the script could exit,
  28.    so that we can be sure any allocated QSessions or QMessages are
  29.    freed properly */
  30. signal on error
  31. signal on syntax
  32. signal on halt
  33. signal on break_c
  34. signal on break_f
  35.  
  36. /* Used to track allocated QSession and QMessage */
  37. session = 0
  38. message = 0
  39.  
  40. /* Note the offset MUST be -204, and not -30 like in many other
  41.    libraries!  Note also that we require amarquee.library v46 or higher */
  42. check = addlib('amarquee.library', 0, -204, 46)
  43.  
  44. /* Here's where we connect to the server... */
  45.  
  46. say "Connecting to server " || serverName || " on port " || portNum || " as " || logName
  47. session = QNewSession(serverName, portNum, logName)
  48. if (session > 0) then 
  49. do
  50.   say "Connection successful.  Commands are:"
  51.   say ""
  52.   say "a wildhostpath   Access control (default is /#?/#?)"
  53.   say "A wildhostpath   Access control for incoming messages (default in no access)"
  54.   say "m hosts=arg2     Send an active message to hosts"
  55.   say "M hosts=string   Send an system message to hosts"
  56.   say "s path=arg2      Set arg2 node value"
  57.   say "S path=arg2      Stream arg2 node value"
  58.   say "r path=newlabel  Rename arg2 node"
  59.   say "D debugstring    Send debug string"
  60.   say "g wildpath       Get a node or nodes"
  61.   say "c wildpath       Subscribe to a node or nodes"
  62.   say "C wildpath       Get&Subscribe to a node or nodes"
  63.   say "k opID           Klear subscriptions (by id or 0 for all)"
  64.   say "d wildpath       Delete a node or nodes"
  65.   say "i                Request info packet"
  66.   say "p                Request ping packet"
  67.   say "v #              Request new privileges (by code bitchord)"
  68.   say "w #              Release existing privileges (by code bitchord)"
  69.   say "! hosts          Kill other clients (requires KILLCLIENTS privilege!)"
  70.   say "$ param=string   Set a parameter with QSetParam()"
  71.   say "? param          Get a parameter by name"
  72.   say "<enter>          Send accumulated transactions (GO!!)"
  73.   say ""
  74.   say "Press CTRL-F to enter commands, or CTRL-C to quit"
  75.   
  76.   infoOpID = -999
  77.   
  78. MainLoop:
  79.   do forever=1
  80.     /* This will block until we get a signal (e.g. CTRL-C) or a QMessage
  81.        arrives over our connection. */
  82.     message = GetNextQMessage(session, -1, 'SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F')
  83.     
  84.     if (message > 0) then do
  85.         say "QMessage received---------"
  86.         say "Status:       " || GetQMessageField(message, 'Status') || " (" || QErrorName(GetQMessageField(message, 'Status')) || ")"
  87.         say "Error Line:   " || GetQMessageField(message, 'ErrorLine')
  88.         say "Message ID:   " || GetQMessageField(message, 'ID')
  89.         say "Path:         " || GetQMessageField(message, 'Path')
  90.         say "Data:         " || GetQMessageField(message, 'Data')
  91.         say "DataLen:      " || GetQMessageField(message, 'DataLen')
  92.         say "ActualLen:    " || GetQMessageField(message, 'ActualLen')
  93.  
  94.         /* If QMessage is in response to a QInfoOp, parse out QRunInfo */
  95.         if (GetQMessageField(message, 'ID') = infoOpId) then do
  96.           say "QRunInfo:"
  97.           say "Avail:         " || GetQMessageField(message, 'Avail')
  98.           say "Alloced:       " || GetQMessageField(message, 'Alloced')
  99.           say "Allowed:       " || GetQMessageField(message, 'Allowed')
  100.           say "CurrentPrivs:  " || GetQMessageField(message, 'CurrentPrivs')
  101.           say "PossiblePrivs: " || GetQMessageField(message, 'PossiblePrivs')
  102.           end
  103.  
  104.         call FreeQMessage(session, message)
  105.         message = 0
  106.       end /* (message > 0) */
  107.       else
  108.       do
  109.         say "GetNextQMessage returned NULL... probably because we caught a signal."
  110.       end
  111.     end /* (session > 0) */
  112. end
  113. else say "Couldn't connect to server, sorry."
  114.  
  115.  
  116. /* Our error handling/cleanup routine starts here */
  117. ERROR:
  118. SYNTAX:
  119. HALT:
  120. BREAK_C:
  121.   say "CTRL-C or error detected in line " || sigl
  122.   if (message > 0) then do
  123.     call FreeQMessage(session, message)
  124.     end
  125.   if (session > 0) then do
  126.     call QFreeSession(session)
  127.     end
  128.   exit
  129.  
  130.  
  131. /* Command processing "subroutine" */
  132. BREAK_F:
  133.   say "CTRL-F detected, now reading user commands from console."
  134.   done = 0
  135.   do while (done = 0)
  136.     say "Enter next command, or just press enter to send all queued commands."
  137.     parse pull cmd args .
  138.     if (length(cmd) = 0) then 
  139.     do
  140.        call QGo(session, 0L)  /* 'QGOF_SYNC|QGOF_NOTIFY' could here instead of 0L */
  141.        done = 1
  142.     end
  143.     else 
  144.     do
  145.        /* parse out args if there is an = sign */
  146.        parse var args arg1 '=' arg2
  147.        
  148.        res = -100
  149.        
  150.             if (cmd = 'A') then res=QSetMessageAccessOp(session, arg1) 
  151.        else if (cmd = 'm') then res=QMessageOp(session, arg1, arg2)
  152.        else if (cmd = 'M') then res=QSysMessageOp(session, arg1, arg2)   
  153.        else if (cmd = 'a') then res=QSetAccessOp(session, arg1)          
  154.        else if (cmd = 's') then res=QSetOp(session, arg1, arg2) 
  155.        else if (cmd = 'S') then res=QStreamOp(session, arg1, arg2) 
  156.        else if (cmd = 'r') then res=QRenameOp(session, arg1, arg2)       
  157.        else if (cmd = 'D') then res=QDebugOp(session, arg1)              
  158.        else if (cmd = 'g') then res=QGetOp(session, arg1)            
  159.        else if (cmd = 'd') then res=QDeleteOp(session, arg1)             
  160.        else if (cmd = 'i') then res=QInfoOp(session)
  161.        else if (cmd = 'c') then res=QSubscribeOp(session, arg1)      
  162.        else if (cmd = 'C') then res=QGetAndSubscribeOp(session, arg1)
  163.        else if (cmd = 'k') then res=QClearSubscriptionsOp(session,arg1) 
  164.        else if (cmd = 'p') then res=QPingOp(session)                             
  165.        else if (cmd = 'v') then res=QRequestPrivilegesOp(session,arg1)  
  166.        else if (cmd = 'w') then res=QReleasePrivilegesOp(session,arg1)  
  167.        else if (cmd = '!') then res=QKillClientsOp(session,arg1)              
  168.        else if (cmd = '?') then res=QGetParameterOp(session,arg1)             
  169.        else if (cmd = '$') then res=QSetParameterOp(session,arg1,arg2)        
  170.  
  171.        if (cmd = 'i') then infoOpId = res
  172.        
  173.        if (res = -100) then say "Unknown command character [" || cmd || "]"
  174.                        else say "Command processed, opCode was " || res
  175.     end
  176.   end
  177.   say "Sending commands and resuming main loop..."
  178.   signal on break_f
  179.   signal MainLoop
  180.